use serde_json::Value;
use reqwest::{self, Error};

pub async fn fetch_gitee_activity(username: &str) -> Result<Vec<ActivityEvent>, Error> {
    let url = format!("https://gitee.com/api/v5/users/{}/events", username);
    let client = reqwest::Client::builder()
        .use_rustls_tls()
        .build()?;
    
    let response = client.get(&url).send().await?;
    
    // 正确调用方式：直接使用实例方法
    let events: Vec<Value> = response.json().await?;

    Ok(events.into_iter().filter_map(|event| {
        match event["type"].as_str() {
            Some("IssueEvent") => Some(ActivityEvent::NewIssue),
            Some("PushEvent") => Some(ActivityEvent::CodeCommit),
            _ => None,
        }
    }).collect())
}

#[derive(Debug)]
pub enum ActivityEvent {
    NewIssue,
    CodeCommit,
}
